1. Field of the Invention
The present invention relates to a method for processing macro instructions and, in preferred embodiments, a method for altering the manner in which macro instructions are generated and processed by an assembler program.
2. Description of the Related Art
Assembly languages are the mixture of two distinct languages, ordinary assembly language and the conditional assembly and macro language. The ordinary assembly language is the language of the machine and assembler instruction statements that the assembler translates into machine language. The conditional assembly language is used primarily in macro instructions. Macro instructions are invoked during assembly to perform useful functions. The conditional assembly language consists of conditional statements, variable symbols, and macros that the assembler interprets and executes at assembly time to tailor, select, and create sequences of statements.
The conditional assembly language includes two classes of symbols, variable symbols and sequence symbols. Variable symbols are used for evaluation and substitution. Evaluation involves assigning values to variable symbols based on the results of computing expressions and substitution involves the assembler substituting the value of the variable symbol at instances of the variable symbol. The selection aspect of the conditional assembly language provides sequence symbols that alter the sequential flow of statement processing by the assembler.
A macro language provides a convenient way to automatically and repetitively generate a sequence of language statements in a single source program. Macros can be used, for example, in assembler languages to generate assembly language statements within a source program. The definition of a macro within a source program includes the name of the macro, variables used as points of substitution within the macro, and the sequence of language statements the assembler generates when the macro is called in the source program. A call to a macro using its defined name causes the assembler to generate the language statements included in the macro within the source program at the point where the call to the macro is made. If the macro includes variables, the assembler will interpret the variables and replace the variables with their values. The processing of a macro, also called macro expansion, consists of making logical decisions based on input arguments such as variables.
Macro processors employ three different mechanisms, text insertion, text parameterization, and text selection. In text insertion, the macro is used to generate a stream of characters to replace the string recognized in the macro call, i.e., inject one stream of source text into another. Text parameterization concerns the tailoring and adaptation of the generated stream to add parameters provided from the main program and other macro-calculated variables into the stream generated by the macro. Text selection concerns the ability to generate alternative streams of characters.
In current macro techniques, macro commands and model statements include fields in a standardized format. These standardized formats allow macro expansion to proceed with greater efficiency because arguments and internal variables are substituted directly into predetermined fields in the model statements. One limitation of this optimized encoding technique is that arbitrary forms of records cannot be created. Only those statements that comply with the pre-defined standard statement format can be used. For instance, a comment statement cannot be generated by substitution. Another limitation is that statements that could affect the assembler's analysis of the structure and content of a macro definition cannot be generated by substitution; this limitation encompasses almost all conditional assembly statements.
In prior art techniques, a nested macro call involves an outer macro making a call to an inner macro. When an inner macro is called within an outer macro, the processing of the outer macro is suspended (stacked) until the assembler completes processing the inner macro. A variable may be defined in an outer macro and passed through one or more levels of the nested inner macros and used therein. The processing of the inner macro may invoke further inner macros. Whenever an inner macro is called (invoked) the invoking macro is preserved (stacked) and the inner macro is processed. Only when the called innermost macro is completed does processing (expansion) of the outer or inner macro from which the most recently called inner macro is called resume. When the outermost macro of the expansion is completed, the assembler returns to processing the primary input stream.
With inner macro calls, the scanning and processing of the statements generated by one macro expansion must be completed before any statements generated by the calling macro(s) continues. Moreover, the order of statement generation is determined by the order of the nesting of the macro calls. The example (1) below shows macro definitions Mac_A and Mac_B, wherein Mac_A makes a call to Mac_B.
Example (1) Macro_Definition_Begin Mac_A P1,P2 Define Mac_A with parameters P1,P2 - - - Processing logic for Mac_A Statements_A1 Statements generated by Mac_A Mac_B RRR,SSS Nested Call on Mac_B Statements_A2 Statements generated by Mac_A Macro_Definition_End Macro_Definition_Begin Mac_B P1,P2 Define Mac_B with parameters P1,P2 - - - Processing logic for Mac_B Statements_B Statements generated by Mac_B Macro_Definition_End
When Mac_A is called, Mac_A generates the statements in the following order:
 Statements_A1 Statements generated by Mac_A Statements_B Statements generated by Mac_B Statements_A2 Statements generated by Mac_A
With the current nested call technique for generating macro statements, statements are generated in an order that matches the nesting of the calls. There is no mechanism for providing further controls over the sequence of generated statements. Thus, although the outer (calling) macro can pass variables and arguments into the inner (called) macro, the outer macro cannot interact with the called macros to alter the sequence of statements generated therein.
A nested definition occurs when a macro is defined within another macro, referred to as the enclosing macro. Thus, the process of generating the statements of the enclosing macro involves generating the statements of a macro definition. After generating the macro definition, the defined macro may be called and expanded as discussed above. The process of generating the outer macro encodes the defined inner macro. Example (2) below shows enclosing macro Mac_F including a nested definition of macro Mac_G.
 Example (2) Macro_Definition_Begin Mac_F P1,P2 Define Mac_F with parameters P1,P2 - - - Processing logic for Mac_F Statements_F1 Statements generated by Mac_F Macro_Definition_Begin Mac_G P1,P2 Define Mac_G with parameters P1,P2 - - - Processing logic for Mac_G Statements_G Statements generated by Mac_G Marco_Definition_End - - - Processing logic for Mac_F Statements_F2 Statements generated by Mac_F Macro_Definition_End
A call on macro Mac_F will generate the statements of the nested definition of Mac_G. If the enclosing macro is called a second time, then the assembler generates a second definition, identical to the first, which replaces the previously generated nested definition. Nested definitions of macros may also be included within nested definitions. As discussed, a nested definition will not be generated until the enclosing macro, which may itself be a nested definition, is invoked. Only after the enclosing macro is called will the nested macro definition be generated, encoded and available for subsequent calls to the generated nested definition.
One limitation of the nested definition technique is that all statements of the inner macro definition are shielded from actions of the enclosing macro. This means that variables defined and used within an inner macro definition cannot be manipulated within the outer macro using the standard techniques of parameterization and selection. The expansion and interpretation of variables and other statements within the inner macro is not affected by the operations or variables used in the outer macro. The outer macro will not have an opportunity to parameterize or manipulate statements or variables set within the inner macro while the inner macro is processed. Moreover, macros containing nested definitions cannot generate partial nested definitions. Nested definitions must be completely generated within the outer macro. This is because the start and end of a macro definition must be matched within each macro; otherwise, the macro processor cannot determine whether or not a macro coding error has occurred. A further limitation of prior art macro processing techniques is that an enclosing macro can only generate a single instance of that definition because generating the definition multiple times results in the assembler's replacing the previous definition with a new definition that is identical to the previously generated definition.
Moreover, the processing within one inner macro cannot effect the processing and operations of another inner macro using the same parameters. Thus, a call to an inner macro cannot set a parameter to a value and pass such values to a subsequent inner macro call. Thus, the shielding effect of macro processing techniques applies to interaction between inner macros as well as interaction between inner and outer macros.
Thus, with prior art macro generation techniques the sequencing of statement generation from macro expansions and nested calls is predetermined. Prior art macros cannot be used to defer the processing of statements or provide a different ordering in the processing of generated statements. Further, the assembler forbids creation by substitution of a large class of statement types. For instance, macros cannot generate macro definitions that have been tailored and/or parameterized in any way. Still further, statements generated during macro expansion must have a fixed and predetermined format that cannot be altered.